(function($, owner) {
	if (!Array.prototype.indexOf)
	{
	  Array.prototype.indexOf = function(elt /*, from*/)
	  {
	    var len = this.length >>> 0;
	    var from = Number(arguments[1]) || 0;
	    from = (from < 0)
	         ? Math.ceil(from)
	         : Math.floor(from);
	    if (from < 0)
	      from += len;

	    for (; from < len; from++)
	    {
	      if (from in this &&
	          this[from] === elt)
	        return from;
	    }
	    return -1;
	  };
	}
	/**
	 * 获取日期
	 * d 0为当前日期 正数往后推 负数往前推
	 * style 0只要年月日 1 缀上 00:00:00 2 缀上23:59:59 其他数字 返回系统时间
	 * delimiter 分割符 如  -  / 
	 */
    owner.GetDate = function(d,style,delimiter) {
    	
    	if(!d){
    		d = 0;
    	}
    	if(!style){
    		style=0;
    	}
    	if(!delimiter){
    		delimiter = "-";
    	}
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate()+d;
		
		var hour = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();

		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (day >= 0 && day <= 9) {
			day = "0" + day;
		}
		if (hour >= 0 && hour <= 9) {
			hour = "0" + hour;
		}
		if (min >= 0 && min <= 9) {
			min = "0" + min;
		}
		if (sec >= 0 && sec <= 9) {
			sec = "0" + sec;
		}
		var dateStr = year + delimiter + month + delimiter + day;
		if(style=="1"){
			dateStr = dateStr + " 00:00:00";
		}else if (style == "2"){
			dateStr = dateStr + " 23:59:59";
		}else{
			dateStr = dateStr + " " +hour+":"+min+":"+sec;
		}
		return dateStr;
	};
	owner.GetYear = function() {
		var date = new Date();
		var year = date.getFullYear();
		return year;
	};
	owner.GetMonth = function() {
		var date = new Date();
		var month = date.getMonth() + 1;
		if(month<10){
			month = "0"+month;
		}
		return month;
	};
	owner.getMonthLastDay = function(y,m){
        // 本月最后一天日期    
        var lastDay = new Date(y,m,0);
        if(m<10){
        	m = "0"+m;
        }
        lastDay = y + "-" + m + "-" + lastDay.getDate() + " 23:59:59";
        return lastDay;
		
	};
	owner.getTableYear = function(startDate,endDate){
		var tableYear = ""; //转存历史表后缀
		if(startDate==""&&endDate==""){
			return tableYear;
		}
		var startYear = startDate.substring(0, 4);//YYYY
		var endYear = endDate.substring(0, 4);//YYYY
		var nowYear = new Date().getFullYear();//获取当前年2019 2020 2021
		var long6Month = Date.parse(nowYear+"/06/30 23:59:59");//当前年6月30号毫秒数
		var longNowDate =  new Date().getTime();//当前时间的毫秒数
		
		if(startYear==nowYear && endYear==nowYear){//如果开始时间和结束日期都在当前年不存在查询历史数据问题 在原始表里查即可
			tableYear = ""
		}else if(longNowDate<long6Month&&nowYear-startYear==1){//如果当前时间小于当前年6月30号 
																//而且开始日期只比当前小一年即去年 在原始表查询数据 因为还没转存
			tableYear = ""
		}else if(longNowDate>long6Month&&nowYear-startYear>0){//当前日期大约6月30号 而且开始日期不为当前年
			if(startYear!=endYear){//查询间隔大于1年时不允许跨年
				Sys.error("日期不可跨年");
				return "false";
			}
			tableYear = "_"+startYear;
		}else if(nowYear-startYear>1){//查询间隔大于1年
			if(startYear!=endYear){//查询间隔大于1年时不允许跨年
				Sys.error("日期不可跨年");
				return "false";
			}
			tableYear = "_"+startYear;
		}
		return tableYear;
	};
}(jQuery, window.vtecommon = {}));
